/**
 * 
 */
package com.ruyipu.forum.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.ruyipu.forum.interfaces.IItem;

/**
 * @author donald
 * 
 */
public abstract class BaseAdapter extends android.widget.BaseAdapter {

	protected Context context;
	protected List<IItem> dataList;

	public BaseAdapter(Context context, List<IItem> dataList) {
		this.context = context;
		this.dataList = dataList;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getCount()
	 */
	public int getCount() {
		return dataList.size();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItem(int)
	 */
	public IItem getItem(int position) {
		return dataList.get(position);
	}

	/*
	 * (non-Javadoc) {
	 * 
	 * @see android.widget.Adapter#getItemId(int)
	 */
	public long getItemId(int position) {
		return position;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	public abstract View getView(int position, View convertView,
			ViewGroup parent);

	protected View getView(View convertView, int resourceId) {
		LinearLayout layout = null;
		if (null == convertView) {
			layout = new LinearLayout(context);
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater li = (LayoutInflater) context
					.getSystemService(inflater);
			li.inflate(resourceId, layout);
		} else {
			layout = (LinearLayout) convertView;
		}
		return layout;
	}
}
